<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>录取分析</el-breadcrumb-item>
      <el-breadcrumb-item>录取名单</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.searchText"
            ><el-button
              slot="append"
              icon="el-icon-search"
              @click="getfexamList()"
            ></el-button> </el-input
        ></el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true"
            >添加录取名单</el-button
          >
        </el-col>
      </el-row>
      <el-divider><i class="el-icon-s-check"></i></el-divider>
      <!-- 考生列表区域 -->
      <el-table :data="fexamlist" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="考号" prop="Eno"></el-table-column>
        <el-table-column label="姓名" prop="Aname"></el-table-column>
        <el-table-column label="专业名称" prop="Cname"></el-table-column>
        <el-table-column label="初试成绩" prop="Fscore"></el-table-column>
        <el-table-column label="复试成绩" prop="Sscore"></el-table-column>
        <el-table-column fixed="right" label="操作" width="95">
          <template>
            <el-tooltip content="编辑" placement="bottom">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                circle
                @click="editDialogVisible = true"
              ></el-button>
            </el-tooltip>
            
            <el-tooltip content="删除" placement="bottom">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                circle
                @click="deleteDialogVisible = true"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        small
        layout="prev, pager, next"
        :total="50"
        :current-page="queryInfo.pagenum"
        :page-size="queryInfo.pagesize"
      >
      </el-pagination>
    </el-card>

    <!-- 添加考生信息 -->
    <el-dialog
      title="添加录取名单"
      :visible.sync="addDialogVisible"
      width="50%"
      @close="addDialogClose()"
    >
      <!--内容主体区域-->
      <el-form
        :model="addForm"
        :rules="addFormRulers"
        ref="addFormRef"
        label-width="110px"
      >
        <el-form-item label="考号" prop="eno">
          <el-input v-model="addForm.eno"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="aname">
          <el-input v-model="addForm.aname"></el-input>
        </el-form-item>
         <el-form-item label="专业名称" prop="cname">
          <el-input v-model="addForm.cname"></el-input>
        </el-form-item>
        <el-form-item label="初试成绩" prop="fscore">
          <el-input v-model="addForm.fscore"></el-input>
        </el-form-item>
        <el-form-item label="复试成绩" prop="sscore">
          <el-input v-model="addForm.sscore"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addfexam">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改考生信息 -->
    <el-dialog
      title="修好录取名单"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="updateDialogClose()"
    >
    <el-form
        :model="updateForm"
        :rules="updateFormRulers"
        ref="updateFormRef"
        label-width="110px"
      >
         <el-form-item label="考号" prop="eno">
          <el-input v-model="updateForm.eno"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="aname">
          <el-input v-model="updateForm.aname"></el-input>
        </el-form-item>
         <el-form-item label="专业名称" prop="cname">
          <el-input v-model="updateForm.cname"></el-input>
        </el-form-item>
        <el-form-item label="初试成绩" prop="fscore">
          <el-input v-model="updateForm.fscore"></el-input>
        </el-form-item>
        <el-form-item label="复试成绩" prop="sscore">
          <el-input v-model="updateForm.sscore"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="showEditDialog"
          >确定修改</el-button
        >
      </span>
    </el-dialog>

    <!-- 删除考生信息 -->
    <el-dialog
      title="删除录取名单"
      :visible.sync="deleteDialogVisible"
      width="50%"
      @close="deleteDialogClose()"
    >
    <el-form
        :model="deleteForm"
        :rules="deleteFormRulers"
        ref="deleteFormRef"
        label-width="110px"
      >
        <el-form-item label="考号" prop="eno">
          <el-input v-model="deleteForm.eno"></el-input>
        </el-form-item>
        
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="showDeleteDialog"
          >确定删除</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
 

<script>
export default {
  name: "admission",
  data() {
    //获取学生信息表的参数
    return {
      queryInfo: {
        searchText: "",
        pagenum: 1,
        pagesize: 2,
      },
      fexamlist: [],
      total: 0,
      // 控制对话框显示与隐藏
      addDialogVisible: false,
      //添加考生的表单
      addForm: {
        eno: "",
        aname:"",
        cname:"",
        fscore:0,
        sscore:0,
      },
      //添加表单的验证对象
      addFormRulers: {
        eno: [{ required: true, message: "请输入考号", trigger: "blur" }],
        aname: [{ required: true, message: "请输入姓名成绩", trigger: "blur" }],
        cname: [{ required: true, message: "请输入专业名称成绩", trigger: "blur" }],
        fscore: [{ required: true, message: "请输入初试成绩成绩", trigger: "blur" }],
        sscore: [
          { required: true, message: "请输入复试成绩成绩", trigger: "blur" },
        ],
      },
      //控制修改用户对话框的显示与隐藏
      editDialogVisible: false,
      //修改考生的表单
      updateForm: {
        eno: "",
        aname:"",
        cname:"",
        fscore:0,
        sscore:0,
      },
      //添加表单的验证对象
      updateFormRulers: {
         eno: [{ required: true, message: "请输入考号", trigger: "blur" }],
        aname: [{ required: true, message: "请输入姓名成绩", trigger: "blur" }],
        cname: [{ required: true, message: "请输入专业名称成绩", trigger: "blur" }],
        fscore: [{ required: true, message: "请输入初试成绩成绩", trigger: "blur" }],
        sscore: [
          { required: true, message: "请输入复试成绩成绩", trigger: "blur" },
        ],
      },
      // 控制对话框显示与隐藏
      deleteDialogVisible: false,
      //删除考生的表单
      deleteForm: {
        eno: "",
      },
      //添加表单的验证对象
      deleteFormRulers: {
        eno: [{ required: true, message: "请输入考号", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getfexamList();
  },
  methods: {
    async getfexamList() {
      const { data: res } = await this.$http.get("/admission" , {
        parmas: this.queryInfo,
      });
      if (res.code != 20000) {
        return this.$message.error("获取录取名单列表失败");
      } else {
        this.fexamlist = res.data.value;
        this.total = res.data.total;
        console.log(res);
      }
    },
    // 监听对话框是否关闭
    addDialogClose() {
      this.$refs.addFormRef.resetFields();
    },
    updateDialogClose(){
      this.$refs.updateFormRef.resetFields();
    },
    deleteDialogClose(){
      this.$refs.deleteFormRef.resetFields();
    },
    // 点击按钮进行校验
    addfexam() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (valid) {
          const { data: res } = await this.$http.post(
            "/admission",
            this.addForm
          );
          console.log(res);
          if (res.code != 20000) {
            this.$message.error("添加录取名单失败");
          } else {
            this.$message.success("添加录取名单成功");
            this.addDialogVisible = false;
            // 刷新考生档案
            this.getfexamList();
          }
        } else {
          return;
        }
      });
    },
    //显示编辑用户的对话框
    showEditDialog() {
      this.$refs.updateFormRef.validate(async (valid) => {
        if (valid) {
          const { data: res } = await this.$http.post(
            "/admission/update",
            this.updateForm
          );
          console.log(res);
          if (res.code != 20000) {
            this.$message.error("修改录取名单失败");
          } else {
            this.$message.success("修改录取名单成功");
            this.editDialogVisible = false;
            // 刷新考生档案
            this.getfexamList();
          }
        } else {
          return;
        }
      });
    },
    // 显示删除用户的对话框
     showDeleteDialog() {
      this.$refs.deleteFormRef.validate(async (valid) => {
        if (valid) {
          const { data: res } = await this.$http.post(
            "/admission/delete",
            this.deleteForm
          );
          console.log(res);
          if (res.code != 20000) {
            this.$message.error("删除录取名单失败");
          } else {
            this.$message.success("删除录取名单成功");
            this.deleteDialogVisible = false;
            // 刷新考生档案
            this.getfexamList();
          }
        } else {
          return;
        }
      });
    },
  },
};
</script>

<style>
.el-breadcrumb {
  margin-bottom: 20px;
  font-size: 12px;
}

.el-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0) !important;
}
</style>